package com.hopu.blb_erp.controller;

import com.hopu.blb_erp.entity.*;
import com.hopu.blb_erp.service.TIomWarehouseService;
import com.hopu.blb_erp.service.TMenuService;
import com.hopu.blb_erp.service.TWarningService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@Api
@RestController
public class StockController {
    @Autowired
    private TIomWarehouseService tIomWarehouseService;
    @Autowired
    private TMenuService tMenuService;
    @ApiOperation("分页库存模糊查询")
    @GetMapping("/stocks/{current}/{pageSize}")
    public ResponseEntity<PageEntity> findPage(@PathVariable("current")Integer current, @PathVariable("pageSize")Integer pageSize,
                                              String iomName, String iomGoods,String iomGoodsno ){
        PageEntity<TIomWarehouse> page = tIomWarehouseService.findPage(current, pageSize,iomName,iomGoods,iomGoodsno);
        List<TIomWarehouse> tIomWarehouses = new ArrayList<>();
        page.getData().forEach(tIomWarehouse -> {
          if (tIomWarehouse.getIomFlag().equals(1)){
              tIomWarehouses.add(tIomWarehouse);
          }
        });
        page.setData(tIomWarehouses);
        return ResponseEntity.ok(page);
    }
    @ApiOperation("根据id查询")
    @GetMapping("/twar")
    public ResponseEntity<List<TIomWarehouse>> findId(){
        List<TIomWarehouse> tIomWarehouses = tIomWarehouseService.selectsAll();
        List<TIomWarehouse> tIomWarehouses1 = new ArrayList<>();
        tIomWarehouses.forEach(tIomWarehouse -> {
          if (  tIomWarehouse.getIomFlag().equals(1)){
              tIomWarehouses1.add(tIomWarehouse);
          }
        });
        return ResponseEntity.ok(tIomWarehouses1);
    }
    @ApiOperation("根据id查询")
    @GetMapping("/stock/{id}")
    public ResponseEntity<TIomWarehouse> findId(@PathVariable("id")Integer id){
         TIomWarehouse byId = tIomWarehouseService.getById(id);
        return ResponseEntity.ok(byId);
    }
}
